<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电影列表</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios0.18.js"></script>
</head>
<body>
<div id="app" style="margin: auto;width: 80%">
    <table>
        <tr>
            <th>海报</th>
            <th>电影名</th>
            <th>时长</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <tr v-for="item in movieList">
            <td style="text-align: center"><img :src="item.movieImgUrl"></td>
            <td style="text-align: center">{{item.movieName}}</td>
            <td style="text-align: center">{{item.movieTime}}分钟</td>
            <td style="text-align: center" v-if="item.movieState == 0">封禁</td>
            <td style="text-align: center" v-if="item.movieState == 1">正常</td>
            <td style="text-align: center" v-if="item.movieState == 0">
                <input type="button" value="解封" @click="changeMovie(item.movieId,1)">
            </td>
            <td style="text-align: center" v-if="item.movieState == 1">
                <input type="button" value="封禁" @click="changeMovie(item.movieId,0)">
            </td>
        </tr>
    </table>
</div>
</body>
</html>
<script>
    new Vue({
        el: "#app",
        data: {
            movieList: []
        },
        methods: {
            getMovieList() {
                let _this = this;
                axios.post("http://localhost:8080/ssm/admin/movieList")
                    .then(function (resp) {
                        console.log(resp.data);
                        if (resp.data.code === 200) {
                            _this.movieList = resp.data.data;
                        } else {
                            alert(resp.data.msg);
                        }
                    });
            },
            changeMovie(mid, state) {
                let _this = this;
                axios.post("http://localhost:8080/ssm/admin/changeMovieState",
                    "movieId=" + mid + "&state=" + state).then((resp) => {
                    console.log(resp.data);
                    if (resp.data.code === 200) {
                        _this.getMovieList();
                    } else {
                        alert(resp.data.msg);
                    }
                });
            }
        },
        mounted() {
            this.getMovieList();
        }
    })
</script>

<style>
    body {
        font-family: Arial, sans-serif;
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    th, td {
        border: 1px solid #ccc;
        padding: 8px;
        text-align: left;
    }

    th {
        background-color: #f2f2f2;
    }

    tr:nth-child(even) {
        background-color: #f2f2f2;
    }

    input[type="button"] {
        background-color: #4CAF50;
        color: white;
        border: none;
        cursor: pointer;
        padding: 5px 10px;
        margin: 4px 2px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 14px;
    }

    img {
        width: 100px;
        height: auto;
    }
</style>
